//多项式相乘
LinkList mulList(LinkList L1, LinkList L2) {
    LinkList L;
    L = (LinkList)malloc(sizeof(Node));
    float arrayL1[100] = { 0 }, arrayL2[100] = { 0 }, arrayR[100] = { 0 };
    int len1, len2,i,j,maxL1,maxL2,minL1,minL2;
    Node* r1, * r2,*p,*q,*s,*r = L;
    r1 = L1->next;
    r2 = L2->next;
    p = L1->next;
    q = L2->next;
    len1 = getLen(L1);
    len2 = getLen(L2);
    //因为上次的链表已经经过从大到小的排序，所以第一个数的下标记为最大指数
    maxL1 = r1->index;//记录L1的最大指数
    maxL2 = r2->index;//记录L2的最大指数
    for (i = 0; i < len1; i++) {//将数组中的值记为0
        arrayL1[i] = 0;
    }
    for (i = 0; i < len2; i++) {
        arrayL2[i] = 0;
    }
    for (i = 0; i < len1 + len2; i++) {
        arrayR[i] = 0;
    }
    //将数组中的值记为0的意义在于，当相对的只数不存在时，系数是0，使程序不会报错
 
    while (r1 != NULL) {
        i = r1->index;
        arrayL1[i] = r1->coef;
        r1 = r1->next;
    }
    while (p->next != NULL) {
        p = p->next;
    }
    minL1 = p->index;//记录L1最小下标
    while (r2 != NULL) {
        i = r2->index;
        arrayL2[i] = r2->coef;
        r2 = r2->next;
    }
    while (q->next != NULL) {
        q = q->next;
    }
    minL2 = q->index;//记录L2最小下标
    for (i = minL1; i <= maxL1; i++) {
        for (j = minL2; j <= maxL2; j++) {
            arrayR[i + j] = arrayL1[i] * arrayL2[j];
        }
    }
    for (i = minL1+minL2; i <= maxL1+maxL2; i++) {
        s = (Node*)malloc(sizeof(Node));
        s->index = i;
        s->coef = arrayR[i];
        r->next = s;
        r = s;
    }
    return L;
}
int main()
{
    LinkList L1, L2,List1,List2,L;
    LinkList R1, R2;
    L1 = LinkListInit();
    L2 = LinkListInit();
    printf("请输入第一个链表的指数和系数：\n");
    List1 = createList(L1);
    printf("请输入第二个链表的指数和系数：\n");
    List2 = createList(L2);
    //L = addList(R);
    sortList(List1);
    sortList(List2);
    //将R1,R2进行行列式相加，防止出现重复的指数
    R1 = addList(List1);
    R2 = addList(List2);
    //将链表进行排序
    sortList(R1);
    sortList(R2);
    L = mulList(R1, R2);
    printLinkList(L);
	return 0;
}